<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="供应商" prop="supplierId">
              <j-search-select-tag v-model="queryParam.supplierId" :async="true" dict="bas_supplier,name,id" />
            </a-form-model-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="销售单号" prop="salOrderWrOrderNo">
              <a-input placeholder="请输入" v-model="queryParam.salOrderWrOrderNo" />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">

          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--   <a-button type="link" @click="handleAdd" icon="plus">新增</a-button>
      <a-button type="link" icon="download" @click="handleExportXls('产品订单')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="link" icon="import">导入</a-button>
      </a-upload> -->
      <!--   <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">删除</a-menu-item>
        </a-menu>
        <a-button type="link" style="margin-left: 8px">批量操作<a-icon type="down" /></a-button>
      </a-dropdown>
      <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length
      }}</a>项
      <a v-if="selectedRowKeys.length > 0" style="margin-left: 12px" @click="onClearSelected">清空</a> -->

      <table-columns-setter v-model="columns" style="float: right;" />
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" bordered rowKey="id" :scroll="{ x: true }" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" class="j-table-force-nowrap"
        :components="drag(columns)" @change="handleTableChange">
        <template #voidedTag="text, record">
          <!-- 使用你的自定义dictTag组件，传递cellValue -->
          <product-task-tag :cell-value="record.status" />
        </template>
        <a slot="supplierId_dictText" @click="myHandleDetail(record)" slot-scope="text, record">{{ text }}</a>
        <!-- <a slot="salOrderWrOrderNo" @click="myHandleDetail(record)" slot-scope="text, record">{{ text }}</a> -->

        <span slot="action" slot-scope="text, record">
          <!-- <a :disabled="record.status !== '1'" @click="handleEdit(record)">生产完成</a>
          <a-divider type="vertical" />
          <a :disabled="!(record.status === '2' || record.status === '4')" @click="handleEdit(record)">质检</a> -->
          <a @click="myHandleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <!-- PRODUCTION_ING(1), // 生产中
               WAIT_QUALITY(2), // 待质检
               DONE(3), //已完成
               NOT_QUALIFIED(4), // 质检不合格 -->
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item @click="handleQualityCheck(record)" key="2">质检</a-menu-item>

              <a-menu-item key="3" @click="Handlepayment(record)">付款</a-menu-item>
              <a-menu-item v-if="record.status == '1'" key="1" @click="handleProductComplete(record)">生产完成</a-menu-item>
            </a-menu>
          </a-dropdown>

        </span>

      </a-table>
    </div>

    <product-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>
import productTaskTag from '@/components/jeecg/JVxeTable/components/cells/productTaskTag.vue'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import productModal from './modules/productModal'
import TableColumnsSetter from '../common/components/TableColumnsSetter'
import { OrderListMixin } from '../common/mixins/OrderListMixin'
import { postAction } from '@/api/manage'
import XEUtils from "xe-utils";
// import {OrderListMixin} from '../common/mixins/OrderListMixin'
export default {
  name: "ProductManagement",
  mixins: [JeecgListMixin, OrderListMixin],
  components: { TableColumnsSetter, productModal, productTaskTag },

  data() {
    return {
      description: '生产任务',
      billReportId: '731513187758551040',
      queryParam: {
        code: '',
        name: '',
      },

      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          fixed: 'left',
          width: 40,
          align: "center",
          customRender: (t, r, index) => parseInt(index) + 1
        },
        {
          title: '供应商名称',
          fixed: 'left',
          width: 160,
          align: "center",
          dataIndex: 'supplierId_dictText',
          scopedSlots: { customRender: 'supplierId_dictText' },
        },
        {
          title: '销售订单号',
          width: 260,
          align: "center",
          dataIndex: 'salOrderWrOrderNo',
          scopedSlots: { customRender: 'salOrderWrOrderNo' },
        },
        {
          title: '附件',
          align: "center",
          dataIndex: 'attachmentUrl'
        },
        {
          title: '备注',
          width: 260,
          align: "center",
          dataIndex: 'remark'
        },
        {
          title: '状态',
          align: "center",
          width: 160,
          dataIndex: 'status',
          ellipsis: true,
          ellipsis: true,
          // 添加自定义渲染插槽
          scopedSlots: {
            customRender: 'voidedTag' // 对应模板中的 #voidedTag 插槽
          }
        },
        {
          title: '完成时间',
          align: "center",
          dataIndex: 'finishTime',
          width: 260,
          customRender: t => !t ? "" : (t.length > 10 ? t.substr(0, 10) : t),
        },
        {
          title: '创建人',
          align: "center",
          width: 160,
          dataIndex: 'createBy_dictText',
          ellipsis: true,
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime',
          width: 260,
          customRender: t => !t ? "" : (t.length > 10 ? t.substr(0, 10) : t),
        },
        {
          title: '操作',
          dataIndex: 'action',
          fixed: 'right',
          width: 180,
          align: "center",
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          },
        }
      ],
      url: {
        list: "/wr/supplierProduceTask/list",
        delete: "/base/basProduct/delete",
        deleteBatch: "/base/basProduct/deleteBatch",
        exportXlsUrl: "/base/basProduct/exportXls",
        importExcelUrl: "/base/basProduct/importExcel",
      },
      dictOptions: {},
    }
  },

  methods: {
    initDictConfig() { },
    handleProductComplete(row) {
      postAction(`/wr/supplierProduceTask/finish?id=${row.id}`, {}).then(res => {
        console.log('生产完成', res);
        // this.productOptions = res.result.productList;
        if (res.code == 200) {
          this.$message.success(res.message);
          this.searchQuery()
        }
      });
    },
    Handlepayment(value) {
      postAction('/wr/supplierProduceTask/pay', { id: value.id }).then(res => {
        console.log('付款的res', res);
        // this.productOptions = res.result.productList;
        if (res.code == 200) {
          this.$message.success(res.message);
        }
      });
      this.searchQuery()
    },
    handleQualityCheck(row) {
      let pass;
      if (row.status === 2) {
        pass = true;
      } else if (row.status === 4) {
        pass = false;
      } else {
        pass = null;
      }
      postAction(`/wr/supplierProduceTask/qualityCheck?id=${row.id}&pass=${pass}`).then(res => {
        console.log('生产完成', res);
        // this.productOptions = res.result.productList;
        if (res.code == 200) {
          this.$message.success(res.message);
          this.searchQuery()
        }
      });
      this.searchQuery()
    },
  }

}
</script>

<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '../common/less/List.less';
</style>
